//package com.jacars.gateway.route;
//
//
//import com.jacars.gateway.service.impl.RouteServiceImpl;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
//import org.springframework.cloud.gateway.route.RouteDefinition;
//import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
//import org.springframework.context.ApplicationEventPublisher;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Flux;
//import reactor.core.publisher.Mono;
//
//@Component
//@Slf4j
//public class RedisRouteDefinitionRepository implements RouteDefinitionRepository {
//
//    private RouteServiceImpl routeService;
//    private ApplicationEventPublisher publisher;
//
//    public RedisRouteDefinitionRepository(ApplicationEventPublisher publisher, RouteServiceImpl routeService) {
//         this.publisher = publisher;
//         this.routeService = routeService;
//    }
//
//    @Override
//    public Flux<RouteDefinition> getRouteDefinitions() {
//        return Flux.fromIterable(routeService.getRouteDefinitions());
//    }
//
//    @Override
//    public Mono<Void> save(Mono<RouteDefinition> route) {
//        return route.flatMap(routeDefinition -> {
//            routeService.save(routeDefinition);
//            //更新动态路由
//            publisher.publishEvent(new RefreshRoutesEvent(this));
//            return Mono.empty();
//        });
//    }
//
//    @Override
//    public Mono<Void> delete(Mono<String> routeId) {
//        return routeId.flatMap(id -> {
//            routeService.delete(id);
//            //更新动态路由
//            publisher.publishEvent(new RefreshRoutesEvent(this));
//            return Mono.empty();
//        });
//    }
//}
